/**
 * 切换笔记类型 1、我的笔记 2、全部笔记
 */
onPageClickFunction = function(pageNumber, event) {
	var pdata = {};
	/*****获取不同的选择课程id******/
	var courseId = $("#search_note_sel").val();
	
	var selectTab = $(".not_right  .exam_title .exam_title01")[0];
	
	/*****************获取当前用户选择的 tab***allnote_div  mynote_div******************/
	if(selectTab){
		if($(selectTab).attr("id") == "allnote_div"){
			pdata.type = "2";
		}
	}
	
	if(courseId>0)
	{
		pdata.course_id = courseId;
	}
	if (pageNumber) {
		pdata.pn = pageNumber;
	}
	AjaxTool("GET", "/student/notes/init?menu=notes", pdata, "html", function(
			data) {
		// 返回内容
		if (data) {
			$("#contentDiv").html(data);
		}
		;
	});
};
function switchNoteType(type) {
	noteData = {
		"type" : type
	};
	getContentDiv("notes", "init", noteData);
}

function addnote() {
	document.getElementById("addnote").style.display = "block";
	$("#add_note_content").val('');
	$("#add_note_title").val('');
}
function getCurrType() {
	if ($("#mynote_div").attr('class') == 'exam_title01')
		return "1";
	else
		return "2";
}
function searchNote() {
	noteData = {
		"type" : getCurrType(),
		"course_id" : $("#search_note_sel").val()
	};
	getContentDiv("notes", "init", noteData);
}
function coolNote(id) {
	$.ajax({
		url : "/student/notes/coolnote",
		type : 'post',
		data : {
			"id" : id
		},
		dataType : 'json',
		success : function(data, status) {
			if (status == "success") {
				if (data.result == "success") {
					alert("点赞已成功！");
					refeshCurrPage();
				} else {
					alert("点赞失败， 请重试");
				}
			}
		},
		error : function(xhr, textStatus, errorThrown) {
			alert("点赞失败， 请重试");
		}
	});
}
function shareNote(id, type) {
	var sharetxt = "分享";
	if (type == 0) {
		sharetxt = "取消分享";
	}
	$.ajax({
		url : "/student/notes/sharenote",
		type : 'post',
		data : {
			"id" : id,
			"type" : type
		},
		dataType : 'json',
		success : function(data, status) {
			if (status == "success") {
				if (data.result == "success") {
					alert(sharetxt + "成功！");
					refeshCurrPage();
				} else {
					alert(sharetxt + "失败， 请重试");
				}
			}
		},
		error : function(xhr, textStatus, errorThrown) {
			alert(sharetxt + "失败， 请重试");
		}
	});
}
function delnote(note, id) {
	$
			.ajax({
				url : "/student/notes/delnote",
				type : 'post',
				data : {
					"id" : id
				},
				dataType : 'json',
				success : function(data, status) {
					if (status == "success") {
						if (data.result == "success") {
							note.parentNode.parentNode.parentNode.parentNode.parentNode
									.removeChild(note.parentNode.parentNode.parentNode.parentNode);
							alert("笔记已删除！");
						} else {
							alert("删除失败， 请重试");
						}
					}
				},
				error : function(xhr, textStatus, errorThrown) {
					alert("删除失败， 请重试");
				}
			});
}
function refeshCurrPage() {
	var currType = getCurrType();
	var currPage = $("#paging_div").pagination('getCurrentPage');
	var title = $("#add_note_title").val();
	var course_id=$("#search_note_sel").val();
	var noteData = {
		"pn" : currPage,
		"type" : currType,
		"course_id":course_id
	};
	getContentDiv("notes", "init", noteData);
}
function saveNote() {
	var title = $("#add_note_title").val();
	var content = $("#add_note_content").val();
	var isShare = $("#add_note_share").is(':checked');
	var share = 0;
	if (isShare) {
		share = 1;
	}
	var course_id = $("#addnote_course_sel").val();
	var saveData = {
		"course_id" : course_id,
		"name" : title,
		"content" : content,
		"share" : share
	};
	$.ajax({
		url : "/student/notes/addnote",
		type : 'post',
		data : saveData,
		dataType : 'json',
		success : function(data, status) {
			if (status == "success") {
				if (data.result == "success") {
					document.getElementById("addnote").style.display = "none";
					alert("添加成功！");
					refeshCurrPage();
				} else {
					alert("添加失败， 请重试");
				}
			}
		},
		error : function(xhr, textStatus, errorThrown) {
			alert("添加失败， 请重试");
		}
	});
}